Skip to content

Conversation

@Zblocker64
Copy link
Collaborator

Description

Closes: #XXXX

This PR resolves critical pagination bugs that were preventing proper page navigation in CLI queries and breaking provider startup order discovery. The issues included:

  1. Missing page number support: CLI --page N flags were not converting to proper offset values
  2. Pagination key corruption: Server-side searchPrefix prepending was corrupting NextKey values for subsequent requests
  3. Mutual exclusivity conflicts: Page keys and offsets could be set simultaneously, causing unpredictable behavior
  4. Array index bug: Bids query had incorrect array access causing runtime panics
  5. Provider startup failures: Key-based pagination failures prevented providers from discovering existing orders during startup

Key Changes:

Client-side fixes:

  • client/utils.go: Added custom ReadPageRequest function with page-to-offset conversion (--page 2offset = (2-1) * limit)
  • client/utils.go: Implemented mutual exclusivity between page keys and offsets
  • client/utils.go: Added Base64 decoding for pagination keys from CLI input
  • Updated all CLI query commands to use custom pagination function:
    • x/provider/client/cli/query.go
    • x/market/client/cli/{order,bid,lease}.go
    • x/deployment/client/cli/query.go
    • x/cert/client/cli/query.go
    • x/audit/client/cli/query.go

Server-side fixes:

  • x/market/keeper/grpc_query.go: Removed searchPrefix corruption that was prepending prefixes to raw SDK NextKey values
  • x/market/keeper/grpc_query.go: Fixed array index bug in Bids query (unsolicited[1]unsolicited[0])
  • Applied fixes to all market query handlers: Orders, Bids, and Leases

Testing:

  • Verified both --page N and --page-key methods return identical results across all query types
  • Confirmed sequential pagination works correctly (page 1 → page 2 → page 3)
  • Tested provider startup order discovery functionality
  • Validated mutual exclusivity prevents conflicts between pagination methods

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

@Zblocker64 Zblocker64 requested a review from a team as a code owner September 15, 2025 13:38
@coderabbitai
Copy link

coderabbitai bot commented Sep 15, 2025

Walkthrough

Adds a new pagination helper ReadPageRequest in client/utils.go and updates multiple CLI commands to call it via a clientutils import alias. No public API signatures changed; x/market/keeper/grpc_query.go only has an end-of-file/formatting change with no functional impact.

Changes

Cohort / File(s) Summary of Changes
Pagination helper
client/utils.go
Adds ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error) to parse pagination flags, validate page vs offset usage, compute offset from page, base64-decode PageKey, and return a populated query.PageRequest or an error.
CLI pagination calls
x/audit/client/cli/query.go, x/cert/client/cli/query.go, x/deployment/client/cli/query.go, x/market/client/cli/bid.go, x/market/client/cli/lease.go, x/market/client/cli/order.go, x/provider/client/cli/query.go
Add clientutils import alias for github.com/akash-network/node/client and replace calls from sdkclient.ReadPageRequest(...) to clientutils.ReadPageRequest(...); no other logic or error-handling changes.
Formatting / EOF
x/market/keeper/grpc_query.go
Minor end-of-file/bracing formatting change only; no behavior, pagination, or API changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant CLI as CLI command
    participant CU as clientutils.ReadPageRequest
    participant GRPC as gRPC query handler

    User->>CLI: run list command with pagination flags
    CLI->>CU: ReadPageRequest(cmd.Flags())
    CU-->>CLI: PageRequest or error
    CLI->>GRPC: Query with PageRequest
    GRPC-->>CLI: Response (items + pagination)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hop through flags and base64 tunes,
Counting pages beneath the moons.
A key decoded, offsets neat,
Commands now call the helper sweet.
Rabbits cheer for pagination blooms. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title is concise, uses a conventional commit prefix, and accurately summarizes the primary user-facing change: fixes to pagination behavior including page-number-to-offset conversion and key-based pagination handling; it directly maps to the client-side ReadPageRequest addition and related CLI updates. It avoids noisy file lists or vague wording and clearly signals the intent to fix pagination regressions. Although the PR also contains server-side adjustments (NextKey handling and an array index fix), centering the title on pagination is appropriate because that is the central visible issue being resolved.
Description Check ✅ Passed The PR description directly describes the changes and rationale, enumerating the client- and server-side fixes, the new ReadPageRequest behavior, affected files, testing performed, and author checklist, which aligns with the provided raw_summary and pr_objectives. It is detailed and clearly related to the changeset rather than off-topic, making it useful for reviewers. The level of detail is sufficient for a lenient description check and documents both the problem and the verification performed.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-ReadPageRequest

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94915eb and 2f1c922.

📒 Files selected for processing (1)
  • x/market/keeper/grpc_query.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/market/keeper/grpc_query.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: lint
  • GitHub Check: coverage
  • GitHub Check: release-dry-run
  • GitHub Check: tests
  • GitHub Check: build-bins

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Zblocker64 Zblocker64 changed the title fix(pagination): resolve page number conversion and key-based paginat… fix(pagination): resolve page number conversion and key-based pagination issues Sep 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments (6)
x/market/client/cli/lease.go (1)

63-66: Misleading help text: “Query order” for a lease getter.

Minor polish for UX.

Apply:

-		Short: "Query order",
+		Short: "Query lease",
x/market/client/cli/bid.go (1)

63-66: Misleading help text: “Query order” for a bid getter.

Apply:

-		Short: "Query order",
+		Short: "Query bid",
x/market/keeper/grpc_query.go (4)

33-41: Defensively reject requests that set both Key and Offset.

Client fixes help, but gRPC should also enforce mutual exclusivity to protect server invariants.

Apply this diff:

 if req.Pagination == nil {
   req.Pagination = &sdkquery.PageRequest{}
 } else if req.Pagination != nil && req.Pagination.Offset > 0 && req.Filters.State == "" {
   return nil, status.Error(codes.InvalidArgument, "invalid request parameters. if offset is set, filter.state must be provided")
 }
+// Defensive: page key and numeric offset are mutually exclusive
+if len(req.Pagination.Key) > 0 && req.Pagination.Offset > 0 {
+  return nil, status.Error(codes.InvalidArgument, "invalid request parameters. set either page key or offset, not both")
+}

189-196: Reverse-search decode fix (unsolicited[0]) is correct.

This removes the off‑by‑index bug and matches the encoder which sets a single flag byte.

For readability, consider a named constant:

+const unsolicitedReverseSearch byte = 1
@@
-    if unsolicited[0] == 1 {
+    if unsolicited[0] == unsolicitedReverseSearch {
       reverseSearch = true
     }

164-172: Add the same key/offset mutual‑exclusion guard for Bids.

Mirror the Orders validation to block ambiguous pagination requests.

Apply this diff:

 if req.Pagination == nil {
   req.Pagination = &sdkquery.PageRequest{}
 } else if req.Pagination != nil && req.Pagination.Offset > 0 && req.Filters.State == "" {
   return nil, status.Error(codes.InvalidArgument, "invalid request parameters. if offset is set, filter.state must be provided")
 }
+if len(req.Pagination.Key) > 0 && req.Pagination.Offset > 0 {
+  return nil, status.Error(codes.InvalidArgument, "invalid request parameters. set either page key or offset, not both")
+}

318-326: Also enforce key/offset mutual exclusivity for Leases.

Keeps all three query handlers consistent and resilient against malformed clients.

Apply this diff:

 if req.Pagination == nil {
   req.Pagination = &sdkquery.PageRequest{}
 } else if req.Pagination != nil && req.Pagination.Offset > 0 && req.Filters.State == "" {
   return nil, status.Error(codes.InvalidArgument, "invalid request parameters. if offset is set, filter.state must be provided")
 }
+if len(req.Pagination.Key) > 0 && req.Pagination.Offset > 0 {
+  return nil, status.Error(codes.InvalidArgument, "invalid request parameters. set either page key or offset, not both")
+}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dcc9fc and a9bfa1d.

📒 Files selected for processing (9)
  • client/utils.go (1 hunks)
  • x/audit/client/cli/query.go (2 hunks)
  • x/cert/client/cli/query.go (2 hunks)
  • x/deployment/client/cli/query.go (2 hunks)
  • x/market/client/cli/bid.go (2 hunks)
  • x/market/client/cli/lease.go (2 hunks)
  • x/market/client/cli/order.go (2 hunks)
  • x/market/keeper/grpc_query.go (3 hunks)
  • x/provider/client/cli/query.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
x/audit/client/cli/query.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/provider/client/cli/query.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/market/client/cli/bid.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/market/client/cli/lease.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/deployment/client/cli/query.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/cert/client/cli/query.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
x/market/client/cli/order.go (1)
client/utils.go (1)
  • ReadPageRequest (13-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: lint
  • GitHub Check: build-bins
  • GitHub Check: tests
  • GitHub Check: coverage
  • GitHub Check: release-dry-run
🔇 Additional comments (2)
x/market/keeper/grpc_query.go (2)

276-291: Keeping Bids NextKey raw and encoding with flags at the end is correct.

LGTM. The token now round‑trips cleanly across boundary pages and reverse index scans.


128-147: Approve — keep SDK NextKey raw

Verified: EncodePaginationKey/DecodePaginationKey are used consistently across grpc_query.go files, util/query/pagination.go provides implementations and tests (util/query/pagination_test.go), and no NextKey+searchPrefix mutations were found. LGTM.

@troian troian merged commit da8666b into main Sep 15, 2025
14 of 17 checks passed
@troian troian deleted the fix-ReadPageRequest branch September 15, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants